import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = '2'
from tensorflow.python.keras.applications.vgg16 import VGG16, preprocess_input, decode_predictions
from tensorflow.python.keras.preprocessing.image import load_img, img_to_array


def predict():
    # 创建模型
    model = VGG16()
    print(model.summary())

    # 获取图片
    image = load_img(path="./image/tiger.jpg", target_size=(224, 224))

    # 将图片转换为数组
    image = img_to_array(image)

    # 将数组转换为四维结构
    image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))

    # 归一化处理
    image = preprocess_input(image)

    # 进行预测
    y_predictions = model.predict(image)

    # 对预测结果进行解码
    y_predictions = decode_predictions(y_predictions)

    print(y_predictions)
    pass


if __name__ == '__main__':
    predict()



